package com.seed.fileud.enumeration;

import cn.hutool.core.util.StrUtil;

public enum ContentType {
    DEFAULT("default","application/octet-stream"),
    JPG("jpg", "image/jpg"),
    TIFF("tiff", "image/tiff"),
    GIF("gif", "image/gif"),
    JFIF("jfif", "image/jpeg"),
    PNG("png", "image/png"),
    TIF("tif", "image/tiff"),
    ICO("ico", "image/x-icon"),
    JPEG("jpeg", "image/jpeg"),
    WBMP("wbmp", "image/vnd.wap.wbmp"),
    FAX("fax", "image/fax"),
    NET("net", "image/pnetvue"),
    JPE("jpe", "image/jpeg"),
    RP("rp", "image/vnd.rn-realpix"),
    MP4("mp4", "video/mp4");

    private String ext;

    private String type;

    public static String getContentType(String fileName) {
        if(StrUtil.isEmpty(fileName)) return DEFAULT.getType();

        String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
        for (ContentType value : ContentType.values()) {
            if(ext.equalsIgnoreCase(value.getExt())){
                return value.getType();
            }
        }

        return DEFAULT.getType();
    }

    ContentType(String ext, String type) {
        this.ext = ext;
        this.type = type;
    }

    public String getExt() {
        return ext;
    }

    public String getType() {
        return type;
    }
}
